/*
 * MediaPlayer.h
 *
 *  Created on: 2018年8月2日
 *      Author: zhengboyuan
 */

#ifndef MEDIAPLAYER_H_
#define MEDIAPLAYER_H_

#include "LibMediaDecoder.h"
#include <string>
#include "TCriticalSection.h"


class MediaPlayerSink
{
public:
    virtual ~MediaPlayerSink() {}

    virtual void onEndOfStream(void* obj) =0;

};


class MediaPlayer
{
public:
	static bool ENABLE_DUMP;

public:
    MediaPlayer();
    virtual ~MediaPlayer();

    virtual void Close() =0;

    virtual bool IsOpen() =0;

    virtual void Stop() =0;

    virtual std::string GetUrl() =0;

	virtual bool Play();

    /// 暂停/恢复
    virtual bool Pause(bool toPause);

    /// 设置倍速
    virtual bool SetScale(double scale);

    /// 获取媒体时长
    virtual int64_t GetDuration();

    /// 获取当前播放时间
    virtual int64_t GetTime();

    /// 拖拽到指定位置
    virtual bool Seek(int64_t pts);

    virtual bool CanSeek();

    /// 抓图
    virtual bool Snap(const char* filepath);


    /// 设置显示比例
    virtual bool SetRatio(int cx, int cy);

    /// 打开声音
    virtual bool OpenSound();

    /// 关闭声音
    virtual bool CloseSound();

	virtual bool IsSoundOpen();

	virtual bool ToggleSound();

    /// 设置音量
    virtual bool SetVolume(int volume);

    /// 获取音量
    virtual int GetVolume();


    virtual void SetSink(MediaPlayerSink* sink);

    virtual bool GetPictureSize(int& width, int& height);

    virtual void EnableDrawTrack(bool enabled);

	virtual void SetVideoWnd(HWND hwnd);

	virtual void SetWndMsg(HWND hwnd, UINT msg);


	virtual bool startRecord(const char* filepath);
	virtual void stopRecord();
	virtual bool isRecording();

	virtual void inputFaceTrack(const char* devID, const char* text, int size);

	HANDLE getHandle();

protected:
	virtual void onOpen();

	static void EventCallback(HANDLE handle, int event, const char* value, int size, void* pUser);
	void EventCallback(int event, const char* value, int size);

protected:
    bool isDecoderOpen();
    void onEndOfStream();
		

protected:
    HANDLE  m_handle;
    MediaPlayerSink*    m_sink;
	HWND m_hwnd;

	HWND m_msgWnd;
	UINT m_msg;

	comn::CriticalSection	m_cs;

};

#endif /* MEDIAPLAYER_H_ */
